<template>
	<view style="padding: 30rpx;">
		<view class="box">
			<uni-forms :modelValue="form" :rules="rules" ref="formRef" label-width="100rpx" label-align="left">
		
				<uni-forms-item label="用户名" name="username">
					<uni-easyinput type="text" v-model="form.username" placeholder="填写用户名" />
				</uni-forms-item>
				<uni-forms-item label="原密码" name="old_password">
					<uni-easyinput type="text" v-model="form.old_password" placeholder="填写原密码"/>
				</uni-forms-item>
				
				<uni-forms-item label="新密码" name="new_password">
					<uni-easyinput type="text" v-model="form.new_password" placeholder="填写新密码" />
				</uni-forms-item>
				
				<uni-forms-item label="确认密码" name="re_password">
					<uni-easyinput type="text" v-model="form.re_password" placeholder="再次填写确认" />
				</uni-forms-item>
			
		
				
				
				<uni-forms-item>
					<button type="primary" size="mini" @click="submit">完成</button>
				</uni-forms-item>
				
			</uni-forms>
		</view>
	</view>
</template>

<script>
	import config from '@/config.js';
	export default {
		data() {
			return {
			
				form: {},
				user: uni.getStorageSync('xm-user'),
				imageStyles: {
					"height": 80, // 边框高度
					"width": 80, // 边框宽度
					"border": { // 如果为 Boolean 值，可以控制边框显示与否
						"color": "#eee", // 边框颜色
						"width": "1px", // 边框宽度
						"style": "solid", // 边框样式
						"radius": "50%" // 边框圆角，支持百分比
					}
				},
				
			}
		},
		onLoad() {
		
		
		},
	methods: {
	  submit() {				
	    let that = this;
	    uni.request({
	      url: config.baseUrl + '/users/updatePWD',
	      data: this.form,
	      method: 'PATCH',
	      success(res) {
	        console.log(res.data);
	        console.log(res.data.code);
	        if (res.data.code === 200) {
	          uni.setStorageSync('xm-user', that.form);
	          console.log(uni.getStorageSync('xm-user'));
	          uni.showToast({
	            icon: "success",
	            title: '修改密码成功',	
	            duration: 2000,
	            success: function() {
	              setTimeout(function() {
	                uni.switchTab({
	                  url: '/pages/my/my'
	                });
	              }, 800);
	            }
	          });
	        } else {
	          uni.showToast({
	            icon: "error",
	            title: res.data.message,
	          });
	        }
	      }
	    });
	  }
	}

	}
</script>

<style>

</style>
